#include "celement.h"
#include <string.h>
#include <iostream>

#include "cmodel.h"
#include "cevent.h"

long CElement::max_id_now=0;
const int CElement::TYPE_MACHINE=1;
const int CElement::TYPE_BUFFER=2;

CElement::CElement()
{
	max_id_now++;
	element_id=max_id_now;
}

CElement::~CElement()
{
}

void CElement::Respond(CEvent* evt)
{
	
}

void CElement::setName(char* str)
{
	strcpy(name,str);
}


void CElement::setType(int tp)
{
	if(tp==CElement::TYPE_MACHINE ||tp==CElement::TYPE_BUFFER)
	{
		element_type=tp;
	}
	else{
		std::cout<<"setType() Failed. A wrong type "<<tp<<" is passed as parameter."<<std::endl;
	}
}

void CElement::AddNextElement(long the_id)
{
	CElement* p=(CElement*)NULL;
	p=theModel->getElementByID(the_id);
	if((CElement*)NULL!=p){
		NextElements.push_back(p);
	}
	else
	{
		std::cout<<"AddElement() Failed!! Element with ID="<<the_id<<" cannot be found."<<std::endl;
	}
}
void CElement::AddPreviousElement(long the_id)
{
	CElement* p=(CElement*)NULL;
	p=theModel->getElementByID(the_id);
	if((CElement*)NULL!=p){
		PreviousElements.push_back(p);
	}
	else
	{
		std::cout<<"AddElement() Failed!! Element with ID="<<the_id<<" cannot be found."<<std::endl;
	}
}

void CElement::AddNextElement(CElement* elm)
{
	NextElements.push_back(elm);
}

void CElement::AddPreviousElement(CElement* elm)
{
	PreviousElements.push_back(elm);
}


void CElement::bindModel(CModel* p_model)
{
	theModel=p_model;
}

long CElement::getID()
{
	return element_id;
}
int CElement::getType()
{
	return element_type;
}